<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>小飞象-会员中心-商品管理</title>
    <link rel="stylesheet" href="//at.alicdn.com/t/font_810097_mgs6xzz1oj.css">
    <link rel="stylesheet" href="css/common/reset.css">
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/reset-layui.css">
    <link rel="stylesheet" href="css/header.css">
    <link rel="stylesheet" href="css/common/nav.css">
    <link rel="stylesheet" href="css/common/aside.css">
    <link rel="stylesheet" href="css/common/content.css">
    <link rel="stylesheet" href="css/goods.min.css">
</head>

<body>
    <header>
        <div class="wrapper">
            <div class="clearfix headerBox">
                <h1 class="fl logo">
                    <a href="">小飞象</a>
                </h1>
                <!-- <div class="fl alipayName">支付宝充值账号: <b class="redColor">156****8656</b>开户人: <b class="redColor">陈小窝</b></div> -->
                <div class="fr logOut">退出</div>
                <div class="fr userName"></div>
            </div>
        </div>
    </header>
    <div class="mhNav">
        <ul class="navMenuBox">
            <li>
                <a href="index.html">
                    飞象首页
                </a>
            </li>
            <li class="memberUser">
                <a href="javascript:;" class="active">
                    会员中心
                </a>
                <ul class="mhColumnSide">
                    <li>
                        <a href="member/basicInfo.html">基本资料</a>
                    </li>
                    <li>
                        <a href="member/storeMage.html">店铺管理</a>
                    </li>
                    <li>
                        <a href="member/readjustNum.html">调整单量</a>
                    </li>
                    <li>
                        <a href="goodsMage.html">商品管理</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="javascript:;">
                    计划管理
                    <!-- <i class="iconfont icon-arrow-up mhArrowIcon"></i>
                        <i class="iconfont icon-arrow-down mhArrowIcon"></i> -->
                </a>
                <ul class="mhColumnSide">
                    <li>
                        <a href="plan/newPlan.html">新建计划</a>
                    </li>
                    <li>
                        <a href="plan/planMage.html">计划管理</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="javascript:;">
                    订单管理
                    <!-- <i class="iconfont icon-arrow-up mhArrowIcon"></i>
                        <i class="iconfont icon-arrow-down mhArrowIcon"></i> -->
                </a>
                <ul class="mhColumnSide">
                    <li>
                        <a href="order/orderMage.html">订单管理</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="javascript:;">
                    资金管理
                    <!-- <i class="iconfont icon-arrow-up mhArrowIcon"></i>
                        <i class="iconfont icon-arrow-down mhArrowIcon"></i> -->
                </a>
                <ul class="mhColumnSide">
                    <li>
                        <a href="capital/inAccout.html">账号充值</a>
                    </li>
                    <li>
                        <a href="capital/transferMage.html">转账管理</a>
                    </li>
                    <li>
                        <a href="capital/orderMage/dailyTaskDes.html">订单信息</a>
                    </li>
                    <li>
                        <a href="capital/expressForm.html">获取快递底单</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="">在线客服</a>
            </li>
        </ul>
    </div>
    <div class="clearfix wrapper mainBomContent">
        <!-- 会员中心-基本资料 -->
        <div class="asideMenu">
            <h2 class="title">
                <i class="iconfont icon--"></i> 会员中心
            </h2>
            <ul>
                <li>
                    <a href="member/basicInfo.html">基本资料</a>
                </li>
                <li>
                    <a href="member/storeMage.html">店铺管理</a>
                </li>
                <li>
                    <a href="member/readjustNum.html">调整单量</a>
                </li>
                <li class="active">
                    <a href="goodsMage.html">商品管理</a>
                </li>
            </ul>
        </div>
        <div class="rightContent">
            <div class="addGoodsView">
                <h2>编辑商品</h2>
                <p class="subtitle">----------------------------------------------------商品基本信息-------------------------------------------------</p>
                <form class="layui-form" lay-filter="goodsFilter">
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品名称：</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="goodsName" disabled>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品主图：</label>
                        <div class="layui-input-block">
                            <img src="" alt="" id="goodsImg" width="128px">
                        </div>
                    </div>
                    <input type="hidden" id="goodsNum">
                    <div class="layui-form-item">
                        <label class="layui-form-label">二维码展示图：</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="qrCodeVal">
                            <div class="layui-upload">
                                <div class="layui-input-inline">
                                    <button type="button" class="layui-btn uploadImgBtn" id="qrCode"></button>
                                </div>
                                <div class="layui-input-inline">
                                    <div class="layui-upload-list">
                                        <img src="" width="128px" id="qrCodeImg">
                                        <p class="demoText"></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <p class="subtitle">-------------------------------------------------商品自定义信息--------------------------------------------------</p>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品简称：</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" placeholder="请输入2-10位中文、数字、英文，简称可以帮助你快速识别商品" id="goodsInfo"
                                lay-verify="required">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">商品重量：</label>
                        <div class="layui-input-block" style="width:550px;">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" placeholder="请输入单件商品的重量" id="weight" lay-verify="required">
                            </div>
                            <label class="layui-form-label" style="width:auto;">KG</label>
                        </div>
                        <p class="warning">温馨提醒：物品重量会显示在物流公司内网中，可在0.5KG至40.00KG之间自行设定</p>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品类别：</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" placeholder="请输入商品中文类别名称，此信息会展示在物流公司内网中" id="category"
                                lay-verify="required">
                        </div>
                    </div>
                    <p class="subtitle">------------------------------------------------商品图片信息（选填）--------------------------------------------</p>
                    <div class="layui-form-item">
                        <label class="layui-form-label">无线端商品主图：</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="imgWirelessVal">
                            <div class="layui-upload">
                                <div class="layui-input-inline">
                                    <button type="button" class="layui-btn uploadImgBtn" id="imgWireless"></button>
                                </div>
                                <div class="layui-input-inline">
                                    <div class="layui-upload-list">
                                        <img src="" width="128px" id="imgWirelessImg">
                                        <p class="demoText"></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">pc端主图：</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="imgPcVal">
                            <div class="layui-upload">
                                <div class="layui-input-inline">
                                    <button type="button" class="layui-btn uploadImgBtn" id="imgPc"></button>
                                </div>
                                <div class="layui-input-inline">
                                    <div class="layui-upload-list">
                                        <img src="" width="128px" id="imgPcImg">
                                        <p class="demoText"></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">手机端搜索主图：</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="imgPhoneVal">
                            <div class="layui-upload">
                                <div class="layui-input-inline">
                                    <button type="button" class="layui-btn uploadImgBtn" id="imgPhone"></button>
                                </div>
                                <div class="layui-input-inline">
                                    <div class="layui-upload-list">
                                        <img src="" width="128px" id="imgPhoneImg">
                                        <p class="demoText"></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">pc端搜索主图：</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="imgEndVal">
                            <div class="layui-upload">
                                <div class="layui-input-inline">
                                    <button type="button" class="layui-btn uploadImgBtn" id="imgEnd"></button>
                                </div>
                                <div class="layui-input-inline">
                                    <div class="layui-upload-list">
                                        <img src="" width="128px" id="imgEndImg">
                                        <p class="demoText"></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">淘口令入口主图：</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="imgCodeVal">
                            <div class="layui-upload">
                                <div class="layui-input-inline">
                                    <button type="button" class="layui-btn uploadImgBtn" id="imgCode"></button>
                                </div>
                                <div class="layui-input-inline">
                                    <div class="layui-upload-list">
                                        <img src="" width="128px" id="imgCodeImg">
                                        <p class="demoText"></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">直通车入口主图：</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="imgTrainVal">
                            <div class="layui-upload">
                                <div class="layui-input-inline">
                                    <button type="button" class="layui-btn uploadImgBtn" id="imgTrain"></button>
                                </div>
                                <div class="layui-input-inline">
                                    <div class="layui-upload-list">
                                        <img src="" width="128px" id="imgTrainImg">
                                        <p class="demoText"></p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <div class="layui-input-inline" style="width:128px;">
                                <button class="layui-btn selectBtn" lay-submit="" lay-filter="addGoods">保存</button>
                            </div>
                            <div class="layui-input-inline" style="width:128px;">
                                <button type="reset" class="layui-btn layui-btn-primary closeBtn">关闭</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script src="js/jquery.min.js"></script>
    <script src="layui/layui.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <script src="js/dataRequest.js"></script>
    <script>
        var mid = $.cookie('id');
        var goodsInfo = JSON.parse($.cookie('goodsInfo'));
        console.log("商品编辑当前商品", goodsInfo);
        if (!mid) {
            window.location.href = "/login.html";
        }
        $(".mhNav .navMenuBox > li > a").click(function (event) {
            if ($(this).siblings('ul').is(':visible')) {
                $(this).siblings('ul').stop(true, true).slideUp();
                $(this).removeClass('active')
            } else {
                $(this).siblings('ul').stop(true, true).slideDown().parents('li').siblings().find('ul').stop(true, true).slideUp();
                $(this).addClass('active').parents('li').siblings().find('a').removeClass('active');
            }
        });
        layui.use(['jquery', 'form', 'upload'], function () {
            var $ = layui.jquery,
                form = layui.form,
                upload = layui.upload,
                layer = layui.layer;
            //二维码展示图
            var uploadInst1 = upload.render({
                elem: '#qrCode'
                , url: IMG_URL
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#qrCodeImg').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code < 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    console.log("二维码图片地址", res.data);
                    $("#qrCodeVal").val(res.data);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('.demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            // 无线端商品主图
            var uploadInst2 = upload.render({
                elem: '#imgWireless'
                , url: IMG_URL
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#imgWirelessImg').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code < 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#imgWirelessVal").val(res.data);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('.demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            // pc端主图
            var uploadInst3 = upload.render({
                elem: '#imgPc'
                , url: IMG_URL
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#imgPcImg').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code < 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#imgPcVal").val(res.data);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('.demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            // 手机端搜索主图
            var uploadInst4 = upload.render({
                elem: '#imgPhone'
                , url: IMG_URL
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#imgPhoneImg').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code < 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#imgPhoneVal").val(res.data);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('.demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            // pc端搜索主图
            var uploadInst5 = upload.render({
                elem: '#imgEnd'
                , url: IMG_URL
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#imgEndImg').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code < 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#imgEndVal").val(res.data);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('.demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            // 淘口令入口主图
            var uploadInst6 = upload.render({
                elem: '#imgCode'
                , url: IMG_URL
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#imgCodeImg').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code < 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#imgCodeVal").val(res.data);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('.demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            // 直通车入口主图
            var uploadInst7 = upload.render({
                elem: '#imgTrain'
                , url: IMG_URL
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#imgTrainImg').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code < 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $("#imgTrainVal").val(res.data);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('.demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
            $.ajax({
                type: "get",
                url: "http://47.92.174.143:8888/v1/client/merchants/" + mid,
                dataType: 'json',
                success: function (data) {
                    console.log("请求数据为", data.data)
                    // 存储总额
                    if (data.data == null || !data.data) {
                        layer.msg('数据出错,请重新登录', {
                            icon: 5,
                            time: 6000,
                            end: function () {
                                location.href = '/login.html';
                            }
                        });
                    } else {
                        $(".userName").html(data.data.loginId);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) { }
            });

            var qrCode = SERVE_URL + goodsInfo.qrCode;
            var imgWireless = SERVE_URL + goodsInfo.imgWireless;
            var imgPc = SERVE_URL + goodsInfo.imgPc;
            var imgPhone = SERVE_URL + goodsInfo.imgPhone;
            var imgEnd = SERVE_URL + goodsInfo.imgEnd;
            var imgCode = SERVE_URL + goodsInfo.imgCode;
            var imgTrain = SERVE_URL + goodsInfo.imgTrain;
            console.log("qrCode+++", qrCode);
            $("#goodsNum").val(goodsInfo.goodsNum);
            $("#goodsName").val(goodsInfo.goodsName);
            $('#goodsImg').attr('src', goodsInfo.goodsImg);
            $('#qrCodeImg').attr('src', qrCode);
            $("#goodsInfo").val(goodsInfo.goodsInfo);
            $("#weight").val(goodsInfo.weight);
            $("#category").val(goodsInfo.category);
            if (goodsInfo.imgWireless == "") {
                $("#imgWirelessVal").val(goodsInfo.goodsImg);
                $('#imgWirelessImg').attr('src', goodsInfo.goodsImg);
            } else {
                $("#imgWirelessVal").val(goodsInfo.imgWireless);
                $('#imgWirelessImg').attr('src', imgWireless);
            }
            if (goodsInfo.imgPc == "") {
                $("#imgPcVal").val(goodsInfo.goodsImg);
                $('#imgPcImg').attr('src', goodsInfo.goodsImg);
            } else {
                $("#imgPcVal").val(goodsInfo.imgPc);
                $('#imgPcImg').attr('src', imgPc);
            }
            $('#imgPhoneImg').attr('src', imgPhone);
            $('#imgEndImg').attr('src', imgEnd);
            $('#imgCodeImg').attr('src', imgCode);
            $('#imgTrainImg').attr('src', imgTrain);
            $("#qrCodeVal").val(goodsInfo.qrCode);
            $("#imgPhoneVal").val(goodsInfo.imgPhone);
            $("#imgEndVal").val(goodsInfo.imgEnd);
            $("#imgCodeVal").val(goodsInfo.imgCode);
            $("#imgTrainVal").val(goodsInfo.imgTrain);
            // form.on('submit(getGoodsDet)', function (data) {
            //     // alert(1);

            //     return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            // });
            // 商品添加
            var id = goodsInfo.id;
            console.log("携带过来的id", id);
            form.on('submit(addGoods)', function (data) {
                var shopId = $("#shopNames option:selected").val();
                console.log("你是我的店铺id", shopId)
                var goodsLink = $("#goodsLink").val();
                var goodsName = $("#goodsName").val();
                var goodsImg = $("#goodsImg").attr("src");
                var goodsInfo = $("#goodsInfo").val();
                console.log("goodsImg", goodsImg);
                var weight = $("#weight").val();
                var category = $("#category").val();
                var goodsNum = parseInt($("#goodsNum").val());
                console.log("goodsNum", goodsNum)
                var qrCodeVal = $("#qrCodeVal").val();
                var imgWirelessVal = $("#imgWirelessVal").val();
                var imgPcVal = $("#imgPcVal").val();
                var imgPhoneVal = $("#imgPhoneVal").val();
                var imgEndVal = $("#imgEndVal").val();
                var imgCodeVal = $("#imgCodeVal").val();
                var imgTrainVal = $("#imgTrainVal").val();
                if (!qrCodeVal) {
                    layer.alert('请上传二维码展示图', { icon: 5 });
                }
                // else if (!imgWirelessVal) {
                //     layer.alert('无线端商品主图', { icon: 5 });
                // } else if (!imgPcVal) {
                //     layer.alert('pc端主图', { icon: 5 });
                // } else if (!imgPhoneVal) {
                //     layer.alert('手机端搜索主图', { icon: 5 });
                // } else if (!imgEndVal) {
                //     layer.alert('pc端搜索主图', { icon: 5 });
                // } else if (!imgCodeVal) {
                //     layer.alert('淘口令入口主图', { icon: 5 });
                // } else if (!imgTrainVal) {
                //     layer.alert('直通车入口主图', { icon: 5 });
                // }
                else {
                    var JdateJson = {
                        "id": id,
                        "shopId": shopId,
                        "goodsLink": goodsLink,
                        "goodsName": goodsName,
                        "goodsImg": goodsImg,
                        "goodsInfo": goodsInfo,
                        "weight": weight,
                        "category": category,
                        "goodsNum": goodsNum,
                        "qrCode": qrCodeVal,
                        "imgWireless": imgWirelessVal,
                        "imgPc": imgPcVal,
                        "imgPhone": imgPhoneVal,
                        "imgEnd": imgEndVal,
                        "imgCode": imgCodeVal,
                        "imgTrain": imgTrainVal,
                    }
                    // return;
                    console.log("JSON.stringify(JdateJson)", JSON.stringify(JdateJson))
                    $.ajax({
                        type: "PUT",
                        url: BASE_URL + MAP_URL + 'goods',
                        dataType: 'json',
                        contentType: "application/json;charset=utf-8",
                        data: JSON.stringify(JdateJson),
                        success: function (data) {
                            console.log("编辑商品数据", data.data)
                            // return;
                            if (data.data == null || !data.data) {
                                layer.msg('数据出错,请重新登录', {
                                    icon: 5,
                                    time: 6000,
                                    end: function () {
                                        location.href = '/login.html';
                                    }
                                });
                            } else {
                                layer.msg('修改商品成功', {
                                    icon: 1,
                                    end: function () {
                                        location.href = '/goodsMage.html';
                                    }
                                });
                            }
                        },
                    });
                }
                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
        })
    </script>
</body>

</html>